#include <iostream>
#include <algorithm>

using namespace std;

static const int MAX = 20000;

int main()
{
    int p[MAX],n;

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> p[i];
    
    int maxv = -2000000;
    int minv = p[0];

    for(int i=0; i<n; i++)
    {
        maxv = max(maxv,p[i] - minv);
        minv = min(minv,p[i]);
    }
    cout<<maxv<<endl;
}

